package com.only4play.practice.pay.reconcile.core.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.only4play.codegen.processor.api.*;
import com.only4play.codegen.processor.creator.GenCreator;
import com.only4play.codegen.processor.creator.IgnoreCreator;
import com.only4play.codegen.processor.dto.GenDto;
import com.only4play.codegen.processor.query.GenQuery;
import com.only4play.codegen.processor.updater.GenUpdater;
import com.only4play.codegen.processor.updater.IgnoreUpdater;
import com.only4play.codegen.processor.vo.GenVo;
import com.only4play.codegen.support.annotation.FieldDesc;
import com.only4play.codegen.support.constants.ValidStatus;
import com.only4play.codegen.support.model.BaseEntity;
import com.only4play.practice.common.enums.pay.OutPayChannelType;
import com.only4play.practice.common.enums.pay.TaskBatchStatusEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;
@GenCreator(pkgName = "com.only4play.practice.pay.reconcile.model.creator")
@GenUpdater(pkgName = "com.only4play.practice.pay.reconcile.model.updater")
// findById方法
@GenVo(pkgName = "com.only4play.practice.pay.reconcile.model.vo")
// findByPage方法
@GenQuery(pkgName = "com.only4play.practice.pay.reconcile.model.query")
@GenCreateRequest(pkgName = "com.only4play.practice.pay.reconcile.model.request")
@GenUpdateRequest(pkgName = "com.only4play.practice.pay.reconcile.model.request")
@GenQueryRequest(pkgName = "com.only4play.practice.pay.reconcile.model.request")
@GenResponse(pkgName = "com.only4play.practice.pay.reconcile.model.response")
@GenDto(pkgName = "com.only4play.practice.pay.reconcile.model.dto")

@GenFeign(pkgName = "com.only4play.practice.pay.reconcile.model.feign")
//
//// 生成serviceImpl
//@GenObjectMapper(pkgName = "com.only4play.practice.pay.reconcile.entitymapper")
//// 生成serviceImpl
//@GenMapper(pkgName = "com.only4play.practice.pay.reconcile.core.mapper")
//@GenService(pkgName = "com.only4play.practice.pay.reconcile.core.service")
//@GenServiceImpl(pkgName = "com.only4play.practice.pay.reconcile.core.service.impl")
//
//@GenController(pkgName = "com.only4play.practice.pay.reconcile.core.controller")
/**
 * @author mengdy
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("pay_reconcile_task_batch")
public class ReconcileTaskBatch extends BaseEntity {

    // 对账渠道名称
    private String channelName;

    @FieldDesc(name = "订单支付渠道")
    private OutPayChannelType channelType;

    /** 商家名称 **/
    private String mchName;

    /** 商家编号 **/
    private String mchNo;

    // 对账任务批次号 = 商户号 + 日期 + 渠道
    private String taskBatchNo;

    // 批次处理状态, 已处理, 未处理
    private Integer handleStatus;

    // 任务创建时间
    private Date taskStartTime;

    // 任务结束时间
    private Date taskEndTime;

    // 账单时间(账单交易发生时间)
    private Date billDate;

    // 账单类型(默认全部是交易成功)
    private String billType;

    // 账单下载开始时间
    private Date downloadStartTime;

    // 账单下载结束时间
    private Date downloadEndTime;


    // 原始对账文件存放地址
    private String orgCheckFilePath;

    // 解析后文件存放地址
    private String releaseCheckFilePath;

    // 对账开始时间
    private Date reconcileStartTime;

    // 对账结束时间
    private Date reconcileEndTime;

    // 对账任务状态结果
    private TaskBatchStatusEnum taskBatchStatus;

    // 所有差错总单数
    private Integer totalMistakeCount;

    // 待处理的差错总单数
    private Integer totalUnHandleMistakeCount;

    // 平台总交易单数
    private Integer totalTradeCount;

    // 渠道总交易单数
    private Integer totalOutTradeCount;

    // 平台交易总金额
    private Long totalTradeAmount;

    // 渠道交易总金额
    private Long totalOutTradeAmount;

    // 平台退款总金额
    private Long totalRefundAmount;

    // 渠道退款总金额
    private Long totalOutRefundAmount;

    // 平台总手续费, 单位元
    private Long fee;

    // 渠道总手续费, 单位元
    private Long outFee;

    // 平台总企业红包退款金额,
    private Long totalEnterpriseRedPacketRefundAmount;

    // 渠道总企业红包退款金额,
    private Long totalOutEnterpriseRedPacketRefundAmount;


    /** 解析检查失败的描述信息 */
    private String checkFailMsg;

    /** 渠道返回的错误信息 */
    private String bankErrMsg;


    /** 状态 */
    @IgnoreUpdater
    @IgnoreCreator
    private ValidStatus validStatus;

    public void init() {
        setValidStatus(ValidStatus.VALID);
    }

    public void valid(){
        setValidStatus(ValidStatus.VALID);
    }

    public void invalid(){
        setValidStatus(ValidStatus.INVALID);
    }

    public ReconcileTaskBatch initEntity(){
        ReconcileTaskBatch reconcileTaskBatch = new ReconcileTaskBatch();
        reconcileTaskBatch.setHandleStatus(0);
        reconcileTaskBatch.setTaskStartTime(new Date());
        reconcileTaskBatch.setTaskBatchStatus(TaskBatchStatusEnum.NEW);
        reconcileTaskBatch.setTotalMistakeCount(0);
        reconcileTaskBatch.setTotalUnHandleMistakeCount(0);
        reconcileTaskBatch.setTotalTradeCount(0);
        reconcileTaskBatch.setTotalOutTradeCount(0);
        reconcileTaskBatch.setTotalTradeAmount(0L);
        reconcileTaskBatch.setTotalOutTradeAmount(0L);
        reconcileTaskBatch.setTotalRefundAmount(0L);
        reconcileTaskBatch.setTotalOutRefundAmount(0L);
        reconcileTaskBatch.setFee(0L);
        reconcileTaskBatch.setOutFee(0L);
        reconcileTaskBatch.setTotalEnterpriseRedPacketRefundAmount(0L);
        reconcileTaskBatch.setTotalOutEnterpriseRedPacketRefundAmount(0L);
        reconcileTaskBatch.setValidStatus(ValidStatus.VALID);
        return reconcileTaskBatch;
    }
}
